import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;


public class Escuta extends Thread {

	private Socket conexao;
	public Escuta(Socket conexao) {
		this.conexao = conexao;
	}

	public void run() {
		try {  

			BufferedReader entrada = new BufferedReader(new InputStreamReader(this.conexao.getInputStream()));  
			PrintStream saida = new PrintStream(this.conexao.getOutputStream()); 
			String msg = entrada.readLine();    

			while (msg != null && !(msg.trim().equals(""))) {  

				System.out.println("Cliente escreveu: "+ msg);  
				saida.println("Servidor diz: recebi sua mensagem=> "+msg);
				msg = entrada.readLine();  
			}    

			this.conexao.close();  
		} catch (IOException e) {             
			System.out.println("Falha na Conexao... .. ." + " IOException: "  
					+ e);  
		}     
	}
}
